#include <cstdio>

__int64 f[ 101 ][ 101 ];
int n, m, x[ 101 ];
int l1, l2, l3, l4, c1, c2, c3, c4;

int mabs( int x ) { return ( x < 0 )?-x :x; }

void init( )
{
    int i, j;
    scanf("%d%d%d%d%d%d%d%d", &l1, &l2, &l3, &l4, &c1, &c2, &c3, &c4);
    scanf("%d%d", &n, &m);
    for ( i = 1; i <= n; i++ )
        scanf("%d", &x[ i ]);
    for ( i = 1; i <= n; i++ )
        for ( j = 1; j <= n; j++ )
        {
            if ( i == j )
                f[ i ][ j ] = 0;
            else if ( mabs( x[ i ] - x[ j ] ) <= l1 )
                f[ i ][ j ] = c1;
            else if ( mabs( x[ i ] - x[ j ] ) <= l2 )
                f[ i ][ j ] = c2;
            else if ( mabs( x[ i ] - x[ j ] ) <= l3 )
                f[ i ][ j ] = c3;
            else if ( mabs( x[ i ] - x[ j ] ) <= l4 )
                f[ i ][ j ] = c4;
            else
                f[ i ][ j ] = 10000000000000LL;
        }
}

void work( )
{
    int i, j, k;
    for ( k = 1; k <= n; k++ )
        for ( i = 1; i <= n; i++ )
            for ( j = 1; j <= n; j++ )
                if ( f[ i ][ j ] > f[ i ][ k ] + f[ k ][ j ] )
                    f[ i ][ j ] = f[ i ][ k ] + f[ k ][ j ];
    while ( m-- )
    {
        scanf("%d%d", &i, &j);
        if ( f[ i ][ j ] < 10000000000000LL )
            printf("The minimum cost between station %d and station %d is %I64d.\n", i, j, f[ i ][ j ]);
        else
            printf("Station %d and station %d are not attainable.\n", i, j);
    }
}

int main( )
{
    int i, t;
    scanf("%d", &t);
    for ( i = 1; i <= t; i++ )
    {
        init( );
        printf("Case %d:\n", i);
        work( );
    }
    return 0;
}
